/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.klikmee.sms.core.base.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceException;

import org.springframework.orm.jpa.JpaCallback;

import com.klikmee.sms.core.model.IncomingMessage;
import com.klikmee.sms.core.model.Service;

/**
 * 
 * @author makcro
 */
public class IncomingMessageDAO extends AbstractDAO<IncomingMessage> implements IncomingMessageFacadeLocal {

	public IncomingMessageDAO() {
		super( IncomingMessage.class );
	}

	public List<IncomingMessage> findByStateAndProvider( final Integer state, final String providerName ) {
		List<IncomingMessage> result = null;

		result = this.entityManager.createNamedQuery( "IncomingMessage.findByStateAndProvider" ).setParameter( "state", state ).setParameter( "provider", providerName ).getResultList();

		return result;
	}

	public List<IncomingMessage> findRange( int[] range ) {
		throw new UnsupportedOperationException( "Not supported yet." );
	}

	public int count() {
		throw new UnsupportedOperationException( "Not supported yet." );
	}

	public IncomingMessage findByProvidersMessageId( final String providersMessageId ) {
		IncomingMessage result = null;

		try {
			result = (IncomingMessage) this.entityManager.createNamedQuery( "IncomingMessage.findByProviderMessageId" ).setParameter( "providerMessageId", providersMessageId ).getSingleResult();
			return result;
		} catch (NoResultException e) {
			return null;
		}
	}

	public List<IncomingMessage> findByStateAndService( Integer state, Service service ) {
		throw new UnsupportedOperationException( "Not supported yet." );
	}

}
